<?php

/**
 * 新闻
 */

namespace app\api\controller\index;

use app\api\controller\Common;

class Index extends Common
{
    protected $data;
    public function initialize()
    {
        parent::initialize();
        $this->data = $this->request->except(['sign', 'accessKey', 'token']);
    }

    public function list()
    {  

        //广告
        $ad1_list = db('ad')
            ->field('id, title, pic, url')
            ->where(['open' => 1, 'as_id' => 1])->order('sort', 'desc')->select();

        //护理推荐
        $ad2_list = db('ad')
            ->field('id, title, pic, url')
            ->where(['open' => 1, 'as_id' => 2])->order('sort', 'desc')->select();

        //爆款商品
        $ad3_list = db('ad')
            ->field('id, title, pic, url')
            ->where(['open' => 1, 'as_id' => 3])->order('sort', 'desc')->select();

        //科普课堂
        $ad4_list = db('ad')
            ->field('id, title, pic, url')
            ->where(['open' => 1, 'as_id' => 4])->order('sort', 'desc')->select();
            
        //联系方式
        $contact_list = db('config')
            ->field('id, name, value')
            ->where(['inc_type' => 'contact1'])->select();
        $contact = [];
        foreach($contact_list as $val){
            $contact[$val['name']] = $val['value'];
        }
            
            return $this->showSuccess('首页', ['ad'=> $ad1_list, 'huli'=> $ad2_list, 'goods'=> $ad3_list, 'kepu'=> $ad4_list, 'contact'=> $contact]);
    }
    
    
}
